//
// Created by Zhang on 2023/5/5.
//

#include <iostream>
#include <memory>
#include <string>
#include "gRpcHelper.h"

#include "../protos/model.grpc.pb.h"

#include <grpcpp/channel.h>
#include <grpcpp/grpcpp.h>

#ifdef BAZEL_BUILD
#include "examples/protos/helloworld.grpc.pb.h"
#include "helloworld.grpc.pb.h"
#endif

using grpc::Channel;
using grpc::ClientContext;
using grpc::Status;

// grpc客户端2
using App::App1;   // 服务
using App::DataUpload;   // 请求
using App::Result;  // 回复
using App::Entity;
using App::Lla;
using App::PosEcf;
using App::VelNue;
using App::VelEcf;

class GreeterApp1 {
public:
    GreeterApp1(std::shared_ptr<Channel> channel):app1(App1::NewStub(channel)) {}

    std::basic_string<char> uploadData(){
        ClientContext context;
        Result result;
        DataUpload dataUpload;

        Status status =  app1->UploadData(&context, dataUpload, &result);
        if (status.ok()) {
            return result.msg();
        } else {
            std::cout << "ERROR: " << status.error_code() << ": " << status.error_message() << std::endl;
            return 0;
        }
    }

private:
    std::unique_ptr<App1::Stub> app1;
};

int app1Test() {
    GreeterApp1 greeter(grpc::CreateChannel("192.168.51.201:7002", grpc::InsecureChannelCredentials()));
    std::basic_string<char> reply = greeter.uploadData();
    std::cout << "Greeter received: " << reply << std::endl;
    return 0;
}


